package com.wps.netConnection
{
	import com.wps.data.NetData;
	
	import mx.messaging.ChannelSet;
	import mx.messaging.channels.AMFChannel;
	import mx.rpc.AbstractOperation;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	import mx.utils.ObjectProxy;

	public class PyService
	{
		public function PyService()
		{
		}
		
		private static var _pyservice: PyService;
		public static function get instance(): PyService
		{
			if(!_pyservice)
			{
				_pyservice = new PyService();
			}
			return _pyservice;
		}
		
		private var _remoteObj: RemoteObject;
		public function get remoteObj(): RemoteObject
		{
			if(!_remoteObj)
			{
				var channel:AMFChannel = new AMFChannel("pyamf", "http://113.76.81.244:4955/burndown/");
				var channels:ChannelSet = new ChannelSet();
				channels.addChannel(channel);
				_remoteObj = new RemoteObject("BurndownService");
				_remoteObj.channelSet = channels;	
			}
			return _remoteObj;
		}
		
		public function getGraphDataAll(callback): void
		{
			var op:AbstractOperation = remoteObj.getOperation("getGraphDataAll");
			op.addEventListener(ResultEvent.RESULT, onGraphDataAll);
			op.addEventListener(FaultEvent.FAULT, onfault);
			op.send();
			function onGraphDataAll(event: ResultEvent): void
			{
				var operation: AbstractOperation = AbstractOperation(event.target);
				var result :Array = operation.lastResult as Array;
				NetData.instance.setResult(result);
				trace(event.target);
				callback(0);
			}
			
			function onfault(event: FaultEvent): void
			{
				trace(event.target);
			}
			
		}
		
		public function login(userName: String, password: String, callback: Function): void
		{
			callback(0);
		}
				
		
		
		
	}
}